



  .syntax unified
  .section .text,"ax",%progbits

  //对外提供的接口
  .global HardFault_Handler
  .global MemManage_Handler
  .global BusFault_Handler
  .global UsageFault_Handler
  .global SVC_Handler
  .global SVC_Call

  //引入声明
  .extern HardFault_IRQ
  .extern MemManage_IRQ
  .extern BusFault_IRQ
  .extern UsageFault_IRQ




  .type Fault_Execute, %function
Fault_Execute:
  MOV       R3,R0
  LDR       R2,=0x00000000

  TST       LR,#0x00000004             //判断使用的堆栈指针
  ITE       EQ
  MRSEQ     R0,MSP
  MRSNE     R0,PSP

  //判断线程是否使用了FPU 如果使用了 保存浮点寄存器
  TST       LR,#0x00000010
  ITTE      EQ
  VSTMDBEQ  R0!, {S16-S31}
  MVNEQ     R1,R2
  MOVNE     R1,R2
  
  STMDB     R0!, {R4-R11}              //保存现场

  BX        R3

  .type HardFault_Handler, %function
HardFault_Handler:
  LDR       R0,=HardFault_IRQ
  B         Fault_Execute

  .type MemManage_Handler, %function
MemManage_Handler:
  LDR       R0,=MemManage_IRQ
  B         Fault_Execute

  .type BusFault_Handler, %function
BusFault_Handler:
  LDR       R0,=BusFault_IRQ
  B         Fault_Execute

  .type UsageFault_Handler, %function
UsageFault_Handler:
  LDR       R0,=UsageFault_IRQ
  B         Fault_Execute

  .type SVC_Handler, %function
SVC_Handler:
  TST       LR,#0x00000004             //判断使用的堆栈指针
  ITE       EQ
  MRSEQ     R2,MSP
  MRSNE     R2,PSP

  LDR       R1,[R2]
  LDR       R0,[R2,#4]
  PUSH      {R2,LR}
  BLX       R1
  POP       {R2,LR}
  STR       R0,[R2]
  
  BX        LR

  .type SVC_Call, %function
SVC_Call:
  SVC       0
  BX        LR



